package
{
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Rectangle;
	
	import mx.containers.Canvas;

	public class Mover extends Canvas
	{
		private var allowDrag:Boolean = false;
		private var dragging:Boolean = false;
		
		public function Mover()
		{
			super();
			width = 15;
			height = 15;
			
			styleName = "dragboxNormal";

			addEventListener(MouseEvent.ROLL_OVER, onThisRollOver);
			addEventListener(MouseEvent.ROLL_OUT, onThisRollOut);
			
			addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
			addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
			addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
		}
		
		private function onMouseDown(e:MouseEvent):void{
			allowDrag = true;
		}

		private function onMouseMove(e:MouseEvent):void{
			if(e.buttonDown){
				if(allowDrag){
					startDrag(false, new Rectangle(0,0, yshow.slide.width - width, yshow.slide.height - height));
					dragging = true;
				}
				dispatchEvent(new Event("dragging"));
			}
			else if(dragging){
				stopDragging();
			}
		}
		
		private function stopDragging():void{
			stopDrag();
			dragging = false;
			allowDrag = false;
		}
		
		private function onMouseUp(e:MouseEvent):void{
			if(dragging){
				stopDragging();
			}
		}
		
		private function onThisRollOver(e:MouseEvent):void{
			styleName = "dragboxOver";
		}
		
		private function onThisRollOut(e:MouseEvent):void{
			styleName = "dragboxNormal";
		}
		
	}
}